package com.itheima.demo;

import com.itheima.domain.AgeOutputBoundsException;
import com.itheima.domain.Student;

import java.util.Scanner;

public class Demo_Student {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        Student stu = new Student();
        System.out.println("请输入学生姓名:");
        String name = sc.nextLine();
        stu.setName(name);
        while (true) {
            try {
                System.out.println("请输入学生年龄:");
                String ageStr = sc.nextLine();
                int age = Integer.parseInt(ageStr);
                stu.setAge(age);
                break;
            } catch (NumberFormatException e) {
                System.out.println("请输入一个整数!");
                continue;
            } catch (AgeOutputBoundsException e) {
                System.out.println("请输入争取范围的年龄!");
                continue;
            }
        }
        System.out.println(stu);
    }
}
